home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / tool / artemis1 / src / sub2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-14  |  10.1 KB  |  515 lines

  1. /*
  2.     ARTemis (Graphic Editor for FM-TOWNS)
  3.     (c) MATSUUCHI Ryosuke 1992
  4.  
  5.     sub2.c
  6.  
  7.     ctox                16進文字を数値に変換
  8.  
  9.     putmsg_width        一定幅によるメッセージ出力
  10.     dispAttentionMsg    注意メッセージ表示
  11.     check_yes_no        確認入力
  12.  
  13.     ms_get                マウス入力
  14.     ms_record_start        マウス動作記録開始
  15.     ms_record_end        マウス動作記録終了
  16.     ms_play_start        マウス動作再生開始
  17.  
  18.     commandMsPlay        マウス動作再生開始コマンド
  19.     commandMsRec        マウス動作記録開始コマンド
  20.     commandMsRecStop    マウス動作記録終了コマンド
  21.  
  22.     moscsr_timer        タイマー形状のマウスカーソルパターンへのポインタ
  23.  
  24.     set_intfunc            一定時間ごとに呼び出す関数の登録
  25.     clr_intfunc                  〃       取消
  26. */
  27.  
  28. #include <stdio.h>
  29. #include <ctype.h>
  30. #include <mos.h>
  31. #include <malloc.h>
  32. #include <fmcfrb.h>
  33. #include "ge.h"
  34. #include "dispman.h"
  35.  
  36.  
  37.  
  38. int ctox(char c)
  39. {
  40.     if ('0'<=c && c<='9')
  41.         return c-'0';
  42.     else if ('a'<=c && c<='f')
  43.         return c-'a'+10;
  44.     else
  45.         return c-'A'+10;
  46. }
  47.  
  48.  
  49. #define    MSG_XLEN    16*12
  50. /*--------------------------------------------------------*/
  51. /*                   注意メッセージ表示                   */
  52. /*--------------------------------------------------------*/
  53.  
  54. // #define    itemOK    2
  55.  
  56. static void dspmsg();
  57.  
  58. #include "sub2.md"
  59.  
  60. void putmsg_width(int x, int y, int width, char *msg, int col)
  61. {
  62.     if (msg == NULL)
  63.         return;
  64.     x += 4;
  65.     y += 4;
  66.     char msgbuf[256],*sp;  int m;
  67.     sp = msg;
  68.     m = 0;
  69.     while (*sp != 0)
  70.     {
  71.         if (*sp == '\n')
  72.         {
  73.             msgbuf[m] = 0;
  74.             ARTputstr12(x,y,msgbuf,col,DMgetmenuplt(White));
  75.             // grp_putstr(x+1,y,msgbuf,Black);
  76.             y += 16;
  77.             m = 0;
  78.             sp++;
  79.         }
  80.         else if ((m+1) >= (width/6))
  81.         {
  82.             msgbuf[m] = 0;
  83.             ARTputstr12(x,y,msgbuf,col,DMgetmenuplt(White));
  84.             // ARTputstr12(x+1,y,msgbuf,Black);
  85.             y += 16;
  86.             m = 0;
  87.         }
  88.         else if (iskanji(*sp))
  89.         {
  90.             msgbuf[m] = *sp;
  91.             msgbuf[m+1] = *(sp+1);
  92.             m += 2;
  93.             sp += 2;
  94.         }
  95.         else
  96.         {
  97.             msgbuf[m] = *sp;
  98.             m++;
  99.             sp++;
  100.         }
  101.     }
  102.     if (m != 0)
  103.     {
  104.         msgbuf[m] = 0;
  105.         ARTputstr12(x,y,msgbuf,col,DMgetmenuplt(White));
  106.         // grp_putstr(x+1,y,msgbuf,Black);
  107.     }
  108. }
  109.  
  110. static char    *msg = NULL;
  111.  
  112. static void dspmsg(int x, int y)
  113. {
  114.     putmsg_width(x,y, MSG_XLEN, msg, DMgetmenuplt(Black));
  115. }
  116.  
  117.  
  118. void    dispAttentionMsg(char *_msg)
  119. {
  120.     msg = _msg;
  121.     DMerasecsr();
  122.     if (menu_dispxy(-2,-2, &attention) != 0)
  123.         return;
  124.     for (;;) {
  125.         DMdispcsr(ms.x, ms.y);
  126.         do {
  127.             ms_get(&ms);
  128.         } while (ms.dx==0 && ms.dy==0 && ms.btn1==OFF && ms.btn2==OFF && key_chk()==0);
  129.         DMerasecsr();
  130.         limitCsrPos();
  131.         if (ms.btn1 == OFFON) {
  132.             int a;
  133.             a = menu_where(ms.x,ms.y,&attention, NULL,NULL,NULL);
  134.             if (a == itemOK)
  135.                 break;
  136.         } else if (ms.btn2 == OFFON)
  137.             break;
  138.     }
  139.     menu_erase();
  140. }
  141.  
  142.  
  143. /*--------------------------------------------------------*/
  144. /*                    確認メニュー表示                    */
  145. /*--------------------------------------------------------*/
  146.  
  147.  
  148. /*
  149. #define    itemGo        2
  150. #define    itemCancel    3
  151. */
  152.  
  153. int check_yes_no(char *_msg)
  154. {
  155.     int r;
  156.     msg = _msg;
  157.     DMerasecsr();
  158.     if (menu_dispxy(-2,-2, &menu_yes_no) != 0)
  159.         return -1;
  160.     for (;;) {
  161.         DMdispcsr(ms.x, ms.y);
  162.         do
  163.         {
  164.             ms_get(&ms);
  165.         } while (ms.dx==0 && ms.dy==0 && ms.btn1==OFF && ms.btn2==OFF && key_chk()==0);
  166.         DMerasecsr();
  167.         limitCsrPos();
  168.         if (ms.btn1 == OFFON) {
  169.             int a;
  170.             a = menu_where(ms.x,ms.y,&menu_yes_no, NULL,NULL,NULL);
  171.             if (a == itemGo)
  172.                 { r = 0;  break; }
  173.             else if (a == itemCancel)
  174.                 { r = -1;  break; }
  175.         }
  176.         else if (ms.btn2 == OFFON)
  177.             { r = -1;  break; }
  178.     }
  179.     menu_erase();
  180.     return r;
  181. }
  182.  
  183.  
  184. /*--------------------------------------------------------*/
  185. /*                   マウスの動作の記録                   */
  186. /*--------------------------------------------------------*/
  187.  
  188.  
  189. #define    MSBUF    100        /* 記録領域の大きさ(キロバイト) */
  190.  
  191.  
  192. static bool ms_recording = NO;
  193. static bool ms_playing = NO;
  194. static int  rec_time0 = 0;        // 記録を開始したときの MOS_getTime 値
  195. static int  play_time0 = 0;        // 再生を開始したときの MOS_getTime 値
  196. static MSDAT play_ms;            // 再生時のマウス状態記録用
  197.  
  198.  
  199. typedef struct
  200. {
  201.     int            time;
  202.     short int    x,y;    // マウス座標
  203.     char        btn;    // 上位4ビット=左ボタン  下位4ビット=右ボタン
  204. } ms_record;
  205.  
  206.  
  207. static ms_record *msbuf = NULL;
  208. static int msbuf_maxnum = 0;
  209. static int msbuf_num = 0;        // 記録/再生時のカウンタ
  210.  
  211.  
  212. static int alloc_msbuf()
  213. // 0:正常終了
  214. {
  215.     if (msbuf == NULL)
  216.     {
  217.         if ((msbuf = malloc(1024*MSBUF)) == NULL)
  218.         {
  219.             dispAttentionMsg("マウス動作の記録のための記憶領域が不足しています");
  220.             return -1;
  221.         }
  222.         msbuf_maxnum = (1024 * MSBUF) / sizeof(ms_record);
  223.     }
  224.     return 0;
  225. }
  226.  
  227.  
  228. void  ms_record_start()
  229. {
  230.     if (alloc_msbuf() == 0)
  231.     {
  232.         dispAttentionMsg("マウス動作記録開始");
  233.         ms_recording = YES;
  234.         rec_time0 = MOS_getTime();
  235.         msbuf_num = 0;
  236.     }
  237. }
  238.  
  239.  
  240. void ms_record_end()
  241. {
  242.     if (ms_recording)
  243.     {
  244.         msbuf[msbuf_num].time = -1;
  245.         ms_recording = NO;
  246.         dispAttentionMsg("マウス動作記録終了");
  247.     }
  248. }
  249.  
  250.  
  251. void ms_play_start()
  252. {
  253.     if (alloc_msbuf() == 0)
  254.     {
  255.         dispAttentionMsg("マウス動作再生開始");
  256.         play_ms = ms;
  257.         ms_playing = YES;
  258.         play_time0 = MOS_getTime();
  259.         msbuf_num = 0;
  260.     }
  261. }
  262.  
  263.  
  264. void  ms_get(MSDAT *ms)
  265. {
  266.     if (ms_playing)
  267.     {
  268.         rdmos(&play_ms);
  269.         if (msbuf[msbuf_num].time == -1 || play_ms.btn1 == OFFON)
  270.         {
  271.             ms_playing = NO;
  272.             ms->btn1 = ms->btn2 = OFF;
  273.             dispAttentionMsg("マウス動作再生終了");
  274.             /* goto _getmouse; */
  275.             return;
  276.         }
  277.         int t;
  278.         t = MOS_getTime() - play_time0;
  279.         if (msbuf[msbuf_num].time <= t)
  280.         {
  281.             int newx,newy;
  282.             newx = msbuf[msbuf_num].x;
  283.             newy = msbuf[msbuf_num].y;
  284.             ms->dx = newx - ms->x;
  285.             ms->dy = newy - ms->y;
  286.             ms->x  = newx;
  287.             ms->y  = newy;
  288.             ms->x  = newx;
  289.             ms->btn1 = (msbuf[msbuf_num].btn >> 4) & 15;
  290.             ms->btn2 = msbuf[msbuf_num].btn & 15;
  291.             msbuf_num++;
  292.             return;
  293.         }
  294.         else
  295.             return;
  296.     }
  297.     else
  298.     {
  299. _getmouse:
  300.         rdmos(ms);
  301.         ;
  302.         static int btn2click = 0;
  303.         static int inter;
  304.         if (ms->btn2 == OFFON)
  305.         {
  306.             inter = MOS_getTime() - btn2click;
  307.             btn2click += inter;
  308.         }
  309.         else
  310.             inter = 10000;
  311.         ;
  312.         if (ms_recording)
  313.         {
  314.             if (msbuf_num >= msbuf_maxnum-1)
  315.             {
  316.                 ms_record_end();
  317.                 return;
  318.             }
  319.             ms_record t;
  320.             t.time = MOS_getTime() - rec_time0;
  321.             t.x = ms->x;
  322.             t.y = ms->y;
  323.             t.btn = ms->btn1 * 16 + ms->btn2;
  324.             if (msbuf_num == 0)
  325.             {
  326.                 msbuf[msbuf_num] = t;
  327.                 msbuf_num++;
  328.             }
  329.             else
  330.             {
  331. #define    PRE    msbuf[msbuf_num-1]
  332.                 if (PRE.x != t.x || PRE.y != t.y || PRE.btn != t.btn)
  333.                 {
  334.                     msbuf[msbuf_num] = t;
  335.                     msbuf_num++;
  336.                 }
  337. #undef PRE
  338.             }
  339.         }
  340.     }
  341. }
  342.  
  343.  
  344. void commandMsPlay()
  345. {
  346.     ms_play_start();
  347. }
  348.  
  349.  
  350. void commandMsRec()
  351. {
  352.     ms_record_start();
  353. }
  354.  
  355.  
  356. void commandMsRecStop()
  357. {
  358.     ms_record_end();
  359. }
  360.  
  361.  
  362. /*--------------------------------------------------------*/
  363. /*                マウスカーソルを定義する                */
  364. /*--------------------------------------------------------*/
  365.  
  366.  
  367. static char *csr_timer[] =
  368. {
  369.     "00000000000000000000000000000000",
  370.     "00000111110000111100001111100000",
  371.     "00011111111001ffff10011111111000",
  372.     "000111111111001111001111111f1000",
  373.     "00111111111000011000011111111100",
  374.     "001f1f1110001111111100011111f100",
  375.     "001ff11100111ffffff111001111f100",
  376.     "0011110111fffff11fffff111011f100",
  377.     "001110011ffffff11ffffff110011100",
  378.     "00010011fff1ffffffff1fff11001000",
  379.     "0000001ffffffff1fffffffff1000000",
  380.     "000001fffffffff1ffffffffff100000",
  381.     "000001ff1ffffff1fffffff1ff100000",
  382.     "000011fffffffff1ffffffffff110000",
  383.     "00001ffffffffff1fffffffffff10000",
  384.     "00001ffffffffff1fffffffffff10000",
  385.     "00001f11fffffff11fffffff11f10000",
  386.     "00001f11fffffff111111fff11f10000",
  387.     "00001ffffffffffffffffffffff10000",
  388.     "00001ffffffffffffffffffffff10000",
  389.     "000011ffffffffffffffffffff110000",
  390.     "000011ff1ffffffffffffff1ff110000",
  391.     "000001ffffffffffffffffffff100000",
  392.     "0000011ffffffffffffffffff1100000",
  393.     "00000011fff1ffffffff1fff11000000",
  394.     "000000111ffffff11ffffff111000000",
  395.     "0000000111fffff11fffff1110000000",
  396.     "0000000011111ffffff1111100000000",
  397.     "00111101101111111111110110111100",
  398.     "011ff1111000111111110001111ff110",
  399.     "01111111100000000000000111111110",
  400.     "00000000000000000000000000000000",
  401.     NULL
  402. };
  403.  
  404.  
  405. static char moscsr[2+512+128];
  406.  
  407.  
  408. char *moscsr_timer()
  409. {
  410.     int i,j;
  411.     // if (moscsr == NULL)
  412.     //    if ((moscsr = malloc(2+512+128)) == NULL)
  413.     //        return NULL;
  414.     moscsr[0] = 4;
  415.     moscsr[1] = 32;
  416.     // パターンデータの作成
  417.     for (i=0; i<32; i++)
  418.     {
  419.         for (j=0; j<16; j++)
  420.         {
  421.             moscsr[2+16*i+j] = ctox(*(csr_timer[i]+2*j  ))
  422.                              + ctox(*(csr_timer[i]+2*j+1))*16;
  423.         }
  424.     }
  425.     // ANDデータの作成
  426.     for (i=0; i<32; i++)
  427.     {
  428.         unsigned long andpat = 0;
  429.         for (j=0; j<32; j++)
  430.         {
  431.             if (ctox(*(csr_timer[i]+j)) != 0)
  432.                 andpat |= (1 << j);
  433.         }
  434.         andpat = ~andpat;
  435.         *(unsigned long *)&moscsr[2+512+4*i]   = (andpat>>24)&255;
  436.         *(unsigned long *)&moscsr[2+512+4*i+1] = (andpat>>16)&255;
  437.         *(unsigned long *)&moscsr[2+512+4*i+2] = (andpat>> 8)&255;
  438.         *(unsigned long *)&moscsr[2+512+4*i+3] = andpat&255;
  439.     }
  440.     return moscsr;
  441. }
  442.  
  443.  
  444. /*--------------------------------------------------------*/
  445. /*            一定時間ごとに関数を呼び出す処理            */
  446. /*--------------------------------------------------------*/
  447.  
  448.  
  449. static bool intenable = NO;
  450. static unsigned int _intfunc_timer = 0;
  451. static unsigned int _intfunc_timeinterval = 0;
  452. static void (*intfunc)();
  453.  
  454.  
  455. static void _call_intfunc()
  456. {
  457.     if (!intenable || intfunc == NOFNC)
  458.         return;
  459.     if (_intfunc_timer >= _intfunc_timeinterval)
  460.     {
  461.         (*intfunc)();
  462.         _intfunc_timer = 0;
  463.     }
  464.     else
  465.         _intfunc_timer++;
  466. }
  467.  
  468.  
  469. int set_intfunc(void (*func)(), int timer)
  470. // 一定時間ごとに呼び出す関数の登録
  471. // timer : 呼び出す時間間隔(1/10 秒単位)
  472. {
  473.     intenable = NO;
  474.     _intfunc_timeinterval = timer;
  475.     _intfunc_timer = _intfunc_timeinterval - 1;
  476.     intfunc = func;
  477.     // return MOS_setEvent(_call_intfunc);
  478.     intenable = YES;
  479.     return 0;
  480. }
  481.  
  482.  
  483. int clr_intfunc()
  484. {
  485.     intenable = NO;
  486.     intfunc = NOFNC;
  487.     // return MOS_setEvent(NOFNC);
  488.     return 0;
  489. }
  490.  
  491.  
  492. static int _timno;
  493.  
  494.  
  495. void int_init()
  496. {
  497.     TIM_TIME timer;
  498.     timer.mode = 0;
  499.     timer.inf  = 0;
  500.     timer.adr  = (unsigned long)_call_intfunc;
  501.     timer.adr_seg = 0;
  502.     timer.hcycle = 0;
  503.     timer.lcycle = 10;
  504.     // TIM_settime(&timer, &_timno);
  505. }
  506.  
  507.  
  508. void int_end()
  509. {
  510.     // TIM_clrtime(_timno);
  511. }
  512.  
  513.  
  514. /* end of sub2.c */
  515.